const User = require("../models/user")

class UserService {
  constructor() {
    this.users = [{ email: "123123@qq.com" }]
  }

  async getAllUsers() {
    return this.users
  }

  async createUser(userData) {
    const newUser = new User(Date.now(), userData.name, userData.email)
    this.users.push(newUser)
    return newUser
  }

  async login(email, password) {
    console.log(email);
    
    const user = this.users.find(u => u.email === email)
    if (!user) {
      throw new Error("用户不存在")
    }
    // 在实际应用中，这里应该进行密码验证
    // 为了演示，我们暂时跳过密码验证
    return {
      success: true,
      code: 200,
      data: [
        {
          createTime: "2025-02-21 13:06:49",
          deptCode: 2,
          modifyTime: "2025-02-21 18:43:36",
          nickName: "admin001",
          password: "12345678",
          policeId: 100000,
          policeName: "预策",
        },
      ],
      message: "登录成功",
      timestamp: 1740451829023,
    }
  }
}

module.exports = new UserService()
